<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>注册 - 课堂问答</title>
    <!-- Bootstrap -->
<!--<link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">-->
<!--你自己的样式文件 -->
<link rel="stylesheet" type="text/css" href="/text01/mynet/quizzhku/1/Public/Css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="/text01/mynet/quizzhku/1/Public/Css/base.css" />
<link rel="stylesheet" type="text/css" href="/text01/mynet/quizzhku/1/Public/Css/fullpage.css" />
<link rel="stylesheet" type="text/css" href="/text01/mynet/quizzhku/1/Public/Css/font-awesome.min.css" />
<!-- <link rel="stylesheet" type="text/css" href="/text01/mynet/quizzhku/1/Public/Css/login.css" /> -->
<!-- <link href="css/your-style.css" rel="stylesheet">      -->   
<!-- 以下两个插件用于在IE8以及以下版本浏览器支持HTML5元素和媒体查询，如果不需要用可以移除 -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- 如果要使用Bootstrap的js插件，必须先调入jQuery -->
<!--<script src="http://cdn.bootcss.com/jquery/2.0.0/jquery.js"></script>-->
<script type="text/javascript" src="/text01/mynet/quizzhku/1/Public/Js/jquery.min.js"></script>
<script type="text/javascript" src="/text01/mynet/quizzhku/1/Public/Js/fullpage.js"></script>
<!-- 包括所有bootstrap的js插件或者可以根据需要使用的js插件调用　-->
<script type="text/javascript" src="/text01/mynet/quizzhku/1/Public/Js/bootstrap.min.js"></script>
<script type="text/javascript" src="/text01/mynet/quizzhku/1/Public/Js/base.js"></script>
<script type="text/javascript" src="/text01/mynet/quizzhku/1/Public/Js/md5.js"></script>
<script type="text/javascript" src="/text01/mynet/quizzhku/1/Public/Js/vue.js"></script>
<script type="text/javascript" src="/text01/mynet/quizzhku/1/Public/Js/Chart.min.js"></script>
    
    <link rel="stylesheet" type="text/css" href="/text01/mynet/quizzhku/1/Public/Css/register.css" />

</head>
<body>
    
    <div class="navbar navbar-inverse" role="navigation">
    <div>
        <div class="navbar-header">
            　<!-- .navbar-toggle样式用于toggle收缩的内容，即nav-collapse collapse样式所在元素 -->
            <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".navbar-responsive-collapse">
                <span class="sr-only">Toggle Navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <!-- 确保无论是宽屏还是窄屏，navbar-brand都显示 -->
            <a href="/text01/mynet/quizzhku/1/index.php" class="navbar-brand">
                <i class="glyphicon glyphicon-book"></i>
                课堂问答系统
            </a>
        </div>
        <!-- 屏幕宽度小于768px时，div.navbar-responsive-collapse容器里的内容都会隐藏，显示icon-bar图标，当点击icon-bar图标时，再展开。屏幕大于768px时，默认显示。 -->
        <div class="collapse navbar-collapse navbar-responsive-collapse">
            <ul class="nav navbar-nav">
                <li><a href="/text01/mynet/quizzhku/1/index.php">首页</a></li>
                <li><a href="##">移动版</a></li>
                <li><a href="##">关于我们</a></li>
                <li><a href="#">帮助</a></li>
            </ul>
            <ul class="nav navbar-nav pull-right">
                <?php if($_SESSION['name']!= null): ?><li><a href="/text01/mynet/quizzhku/1/index.php/Home/TeaClass/classes">进入管理 <i class="fa fa-long-arrow-right"></i></span></a></li>
                <?php else: ?>
                    <li><a href="/text01/mynet/quizzhku/1/index.php/Home/Auth/login"><span class="glyphicon glyphicon-log-in"></span> 登陆</a></li>
                    <li><a href="/text01/mynet/quizzhku/1/index.php/Home/Auth/register">注册</a></li><?php endif; ?>
            </ul>
        </div>
    </div>
</div>
        

    
    <div class="container">
        <div class="alert alert-danger hidden" role="alert"></div>
        <div class="row regis-form">
            <div class="col-md-4 col-md-offset-4">
                <div class="panel paenl-default">
                    <div class="panel-body">
                        <div class="form-top">
                            <div class="form-top-left">
                                <h3 class="mytitle">教师注册</h3>
                            </div>
                            <div class="form-top-right">
                                <button class="btn btn- btn-link" id="switch-ident">学生注册<span class="glyphicon glyphicon-chevron-right"></span></button>
                            </div>
                        </div>
                        <div class="form-body">
                            <form class="col-md-4" id="register-form">
                                <div class="form-group has-feedback" id="email">
                                    <input type="email" class="form-control" placeholder="请输入邮箱"
                                           required>
                                    <span class="help-block"></span>
                                    <span class="glyphicon form-control-feedback hidden"></span>
                                </div>
                                <div class="form-group" id="choose_college">
                                    <select class="form-control">
                                        <option value="select">选择学校</option>
                                        <option value="123">仲恺</option>
                                        <?php if(is_array($college)): foreach($college as $key=>$vo): ?><option value="<?php echo ($vo["col_id"]); ?>"><?php echo ($vo["col_name"]); ?></option><?php endforeach; endif; ?>
                                    </select>
                                </div>
                                <div class="form-group has-feedback" id="teacher_id">
                                    <input type="text" class="form-control" placeholder="请输入您的教师证号" 
                                           required pattern="^[a-zA-Z0-9]+$" max="10">
                                    <span class="help-block"></span>
                                    <span class="glyphicon form-control-feedback hidden"></span>
                                </div>
                                <div class="form-group" id="name">
                                    <input type="text" class="form-control" 
                                           placeholder="请输入您的真实姓名" required>
                                </div>
                                <div class="form-group has-feedback" id="password">
                                    <input type="password" class="form-control" 
                                           placeholder="请输入您的密码" required>
                                    <span class="help-block"></span>
                                    <span class="glyphicon form-control-feedback hidden"></span>
                                </div>
                                <div class="form-group has-feedback" id="password2">
                                    <input type="password" class="form-control" 
                                           placeholder="确认密码" required>
                                    <span class="help-block"></span>
                                    <span class="glyphicon form-control-feedback hidden"></span>
                                </div>
                                <input type="submit" id="register" class="btn btn-primary btn-lg" value="注册" alt="注册"/>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        $(function(){
            // 获取对象
            var input_email = $("#email > input");
            var input_choose_college = $("#choose_college > select");
            var input_teacher_id = $("#teacher_id > input");
            var input_name = $("#name > input");
            var input_pwd = $("#password > input");
            var input_pwd2 = $("#password2 > input");
            var div_email = $("#email");
            var div_choose_college = $("#choose_college");
            var div_teacher_id = $("#teacher_id");
            var div_name = $("#name");
            var div_pwd = $("#password");
            var div_pwd2 = $("#password2");
            var submitBtn = $("#register");
            //切换
            var btn_switch = $("#switch-ident");
            var curr_state = true;
            var title = $(".mytitle");
            //转换
            var switchMess;
            (switchMess = function () {
                if (curr_state) {
                    title.html("教师注册");
                    input_teacher_id.attr("placeholder","请输入您的教师证号");
                    removeErrorSuccess(div_email,input_email);
                    removeErrorSuccess(div_teacher_id,input_teacher_id);
                    removeErrorSuccess(div_name,input_name);
                    removeErrorSuccess(div_pwd,input_pwd);
                    removeErrorSuccess(div_pwd2,input_pwd2);
                    btn_switch.html("学生注册");
                } else {
                    title.html("学生注册");
                    input_teacher_id.attr("placeholder","请输入您的学生证号");
                    removeErrorSuccess(div_email,input_email);
                    removeErrorSuccess(div_teacher_id,input_teacher_id);
                    removeErrorSuccess(div_name,input_name);
                    removeErrorSuccess(div_pwd,input_pwd);
                    removeErrorSuccess(div_pwd2,input_pwd2);
                    btn_switch.html("教师注册");
                }
            })();
            btn_switch.click(function() {
                $(this).blur();
                curr_state = !curr_state;
                switchMess();
            });

            // 监听email变化
            input_email.change(function() {
                var email =input_email.val();
                if (/^[a-z0-9\.\-\_]+\@[a-z0-9\-\_]+(\.[a-z0-9\-\_]+){1,4}$/.test(email) === false) {
                    addError(div_email, "请输入正确的邮箱格式");
                    return;
                }
                postApi("/text01/mynet/quizzhku/1/index.php/Home/Auth/check_email", {email:email}, function(err, data) {
                    if (err) {
                        addError(div_email,"邮箱已存在");
                        input_email.focus();
                    } else {
                        addSuccess(div_email);
                    }
                });
            });

            handle_change = function() {
                showError("");
                var col_id = input_choose_college.val();    // 学校id号
                var tea_number = input_teacher_id.val();
                // 教职证号不为空时才提交
                //教师

                if (tea_number !== ""&&curr_state) {
                    postApi("/text01/mynet/quizzhku/1/index.php/Home/Auth/check_tea_number", {tea_number: tea_number, college_col_id: col_id},
                            function (err, data) {
                                if (err) {
                                    addError(div_teacher_id, "当前学校下教师证号已存在");
                                    input_teacher_id.focus();
                                } else {
                                    addSuccess(div_teacher_id);
                                }
                            });
                }
                //学生？？？
                else if(tea_number !== ""&&!curr_state) {
                    postApi("/text01/mynet/quizzhku/1/index.php/Home/Auth/check_stu_number", {stu_number: tea_number, col_id: col_id},
                            function (err, data) {

                                if (err) {
                                    addError(div_teacher_id, "当前学校下学生证号已存在");
                                    input_id.focus();
                                } else {
                                    addSuccess(div_teacher_id);
                                }
                            });
                }
            };

            // 用同一个函数监听学校选择框和老师id填写框
            input_choose_college.change(handle_change);
            input_teacher_id.change(handle_change);

            // 监听两个密码输入框
            input_pwd2.change(function() {
                var pwd = input_pwd.val();
                var pwd2 = input_pwd2.val();
                // 两次输入不同时，清空确认的输入框，并将焦点定位到第一个输入框
                if (pwd !== pwd2) {
                    addError(div_pwd, "两次输入的密码不同");
                    addError(div_pwd2, "");
                    input_pwd.focus();
                    input_pwd2.val("");
                } else {
                    addSuccess(div_pwd);
                    addSuccess(div_pwd2);
                }
            });

            // 提交表单
            $("#register-form").submit(function(e){
                e.preventDefault(); // 阻止表单的提交
                $(this).blur();
                var email = input_email.val();
                var choose_college = input_choose_college.val();
                var teacher_number = input_teacher_id.val();
                var name = input_name.val();
                var pwd = input_pwd.val();
                var pwd2 = input_pwd2.val();

                if (email === "") {
                    showError("登录号不能为空");
                    return;
                }
                if (choose_college === "") {
                    showError("请选择一个学校");
                    return;
                }
                if (teacher_number === "") {
                    showError("教职工号不能为空");
                    return;
                }
                if (pwd === "" || pwd2 === "") {
                    showError("密码不能空");
                    return;
                }
                if (pwd !== pwd2) {
                    showError("两次密码不一致");
                    return;
                }
                //教师
                if (curr_state) {
                    postData = {
                        tea_email: email, college_col_id: choose_college,
                        tea_number:teacher_number,tea_name: name,tea_password_hash: CryptoJS.MD5(pwd).toString()
                    };
                    postApi("/text01/mynet/quizzhku/1/index.php/Home/Auth/tea_register", postData, function (err, data) {
                        if (err) {
                            showError(err.message);
                        } else {
                            //所有验证都已经通过,跳转到主页面
                            window.location.href = "/text01/mynet/quizzhku/1/index.php/Home/Auth/login";
                        }
                    });
                }
                //学生
                else
                {
                    postData = {
                        stu_email: email, col_id: choose_college,
                        stu_number: teacher_number, stu_name: name, stu_password_hash: CryptoJS.MD5(pwd).toString()
                    };
                    postApi("/text01/mynet/quizzhku/1/index.php/Home/Auth/stu_register", postData, function (err, data) {
                        if (err) {
                            showError(err.message);
                        } else {
                            //所有验证都已经通过,跳转到主页面
                            window.location.href = "/text01/mynet/quizzhku/1/index.php/Home/Auth/login";
                        }
                    });
                }
            });
        });
    </script>

</body>